package pers.jsan.litheopen.security.oauth;

public class UserContextHolder {

    private static ThreadLocal<UserContext> contextHolder = new InheritableThreadLocal<>();

    public static UserContext get() {
        UserContext userContext = contextHolder.get();
        if (userContext == null) {
            userContext = new UserContext();
            contextHolder.set(userContext);
        }
        return userContext;
    }

    public static void set(UserContext userContext) {
        contextHolder.set(userContext);
    }

    public static void clear() {
        contextHolder.remove();
    }
}
